import Vue from 'vue'
import Router from 'vue-router'

import Layout from '@/layout'

Vue.use(Router)

export const constantRoutes = [
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '',
        name: '首页',
        component: () => import('@/views/Home')
      },
      {
        path: 'range',
        name: '排行',
        component: () => import('@/views/Range')
      },
      {
        path: 'active',
        name: '动态',
        component: () => import('@/views/Active')
      },
      {
        path: 'personal',
        name: '个人中心',
        component: () => import('@/views/Personal')
      },
      {
        path: 'register',
        name: '注册',
        component: () => import('@/views/Register')
      },
      {
        path: 'login',
        name: '登录',
        component: () => import('@/views/Login')
      }
    ]
  }
]

const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
